﻿using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Sausage.Common;
using Sausage.Web.Code;
using Sausage.Web.Domain;
using Sausage.Web.Models;

namespace Sausage.Web.Controllers
{
    public class HomeController : Controller
    {
        [HandleError(Order = 3, ExceptionType = typeof(UnauthenticatedException), View = "Unauthenticated")]
        [HandleError(Order = 2, ExceptionType = typeof(UnauthorizedException), View = "Unauthorized")]
        [HandleError(Order = 1, ExceptionType = typeof(Exception), View = "Exception")]
        [ValidateInput(false)]
        public ActionResult Index()
        {
            if (!this.Request.IsAuthenticated)
                return RedirectToAction("User", "Login");
            return View();
        }


        [HandleError(ExceptionType = typeof(Exception), View = "Exception")]
        public ActionResult Logout()
        {
            if (this.Request.IsAuthenticated)
            {
                var principal = this.HttpContext.User as UserPrincipal;
                Authentication.Logout();
            }

            return Redirect("~/Login");
        }
    }
}
